package com.yxt.qmgf.number.vo;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ScoreRecord implements Serializable {
    private static final long serialVersionUID = 1L;

    private String username;
    private String name;
    private int difficulty;
    private int time;
    private int mistakes;
    private int score;
    private long timestamp;

    public ScoreRecord(String username, String name, int difficulty, int time, int mistakes, long timestamp) {
        this.username = username;
        this.name = name ;
        this.difficulty = difficulty;
        this.time = time;
        this.mistakes = mistakes;
        this.timestamp = timestamp;
        this.score = calculateScore();
    }

    private int calculateScore() {
        int baseScore = 1000;
        int timePenalty = time / 10; // 每10秒减1分
        int mistakePenalty = mistakes * 5; // 每个错误减5分
        int difficultyBonus = difficulty * 200; // 难度加成

        return Math.max(0, baseScore - timePenalty - mistakePenalty + difficultyBonus);
    }

    // Getters
    public String getUsername() { return username; }
    public String getName() { return name; }
    public int getDifficulty() { return difficulty; }
    public int getTime() { return time; }
    public int getMistakes() { return mistakes; }
    public int getScore() { return score; }
    public long getTimestamp() { return timestamp; }

    public String getFormattedTime() {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date(timestamp));
    }

    public String getDifficultyName() {
        switch (difficulty) {
            case 1: return "简单";
            case 2: return "中等";
            case 3: return "困难";
            default: return "未知";
        }
    }
}